package collections;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class List_LinkedListTest{
    public static void main(String args[]) {
            List<String> linkedList = new LinkedList<String>();
            linkedList.add("苹果");
            linkedList.add("华为");
            linkedList.add("小米");
            linkedList.add("MOTO");
            System.out.println("直接输出：" + linkedList);
            System.out.println("LinkedList的直接for遍历: ");
            for (int i = 0; i < linkedList.size(); i++) {
                System.out.println(linkedList.get(i));
            }
            //这种一般没人用
            Object[] tempArray = linkedList.toArray();
            System.out.println("LinkedList转换成数组之后再for遍历数组: ");
            for (int i = 0; i < tempArray.length; i++) {
                System.out.println(tempArray[i]);
            }
            
            System.out.println("增强for直接遍历：");
            for (String string : linkedList) {
                System.out.println(string);
            }
            
            System.out.println("迭代器遍历：");
            Iterator<String> iterator = linkedList.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
        }
}